package com.sgu6.sgu6_machine.ui.activity;

import android.graphics.Color;
import android.os.Bundle;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.Toolbar;
import androidx.fragment.app.DialogFragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;

import android.view.MenuItem;

import com.sgu6.sgu6_machine.R;
import com.sgu6.sgu6_machine.adapter.ErrorCodeAdapter;
import com.sgu6.sgu6_machine.base.BaseA;
import com.sgu6.sgu6_machine.dto.ErrorCodeDto;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class ErrorCodeA extends BaseA {


    @BindView(R.id.toolbar)
    Toolbar toolbar;
    @BindView(R.id.rvErrorCode)
    RecyclerView rvErrorCode;

    private List<ErrorCodeDto> codes= new ArrayList<>();

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_error_code);
        ButterKnife.bind(this);

        initUI();
        initParams();
        ErrorCodeAdapter adapter = new ErrorCodeAdapter(this, codes);
        rvErrorCode.setLayoutManager(new LinearLayoutManager(this));
        rvErrorCode.setAdapter(adapter);
    }

    private void initParams(){
        codes.add(new ErrorCodeDto("E1","超温上限值"));
        codes.add(new ErrorCodeDto("E2","加热时间上限值"));
        codes.add(new ErrorCodeDto("E3","碾米电机运动时间上限值"));
        codes.add(new ErrorCodeDto("E4","下米电机运动时间上限值"));
        codes.add(new ErrorCodeDto("E5","拉膜电机运动时间上限值"));
        codes.add(new ErrorCodeDto("E6","封膜电机运动时间上限值"));
        codes.add(new ErrorCodeDto("E7","开门最大时间"));
        codes.add(new ErrorCodeDto("E8","关门最大时间"));
        codes.add(new ErrorCodeDto("E9","最大取货时间"));
        codes.add(new ErrorCodeDto("E10","送谷电机运动时间上限值"));
        codes.add(new ErrorCodeDto("E11","送膜电机运动时间上限值"));
        codes.add(new ErrorCodeDto("E12","精度电机最大复位步数"));
        codes.add(new ErrorCodeDto("E13","总电流限制"));
        codes.add(new ErrorCodeDto("E14","碾米电机电流上限"));
        codes.add(new ErrorCodeDto("E15","送谷电机电流上限"));
        codes.add(new ErrorCodeDto("E16","拉膜电机电流上限"));
        codes.add(new ErrorCodeDto("E17","封膜电机电流上限"));
        codes.add(new ErrorCodeDto("E18","开关门电机电流上限"));
    }

    @Override
    public void initUI() {
        initToolbar();

    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if (item.getItemId() == android.R.id.home) {
            finish();
        }
        return true;
    }

    private void initToolbar() {
        toolbar.setTitle("机器故障代码说明");
        toolbar.setTitleTextColor(Color.WHITE);
        toolbar.setBackgroundResource(R.color.colorPrimaryDark);
        setSupportActionBar(toolbar);

        getSupportActionBar().setHomeButtonEnabled(true);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setDisplayShowTitleEnabled(true);
    }
}
